package com.ywu.data.source.standard.source.field.impl;

import com.ywu.data.source.standard.dto.YwuDataTableFieldDto;
import com.ywu.data.source.standard.entity.YwuDataTableEntity;
import com.ywu.data.source.standard.source.field.YwuDataSourceFieldSqlBuild;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @ClassName YwuBuildFieldDefaultValueSql
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/10/28 20:27
 * @Version 1.0
 **/
@Component
@Order(6)
@Slf4j
public class YwuBuildFieldDefaultValueSql implements YwuDataSourceFieldSqlBuild {

    @Override
    public String buildSql(YwuDataTableEntity ywuDataTableEntity, YwuDataTableFieldDto ywuDataTableFieldDto) {
        // 自增长数据无法设置，默认值
        if (ywuDataTableFieldDto.getAutoIncrement()) {
            return "";
        }
        if (StringUtils.isNotEmpty(ywuDataTableFieldDto.getDefaultValue())) {
            return String.format("DEFAULT '%s' ", ywuDataTableFieldDto.getDefaultValue());
        } else {
            return "";
        }
    }
}
